package com.zhuanzhuan.hero.user.mq.consumer;

import com.bj58.youpin.common.utils.json.JsonUtils;
import com.zhuanzhuan.hero.user.consts.Consts;
import com.zhuanzhuan.hero.user.mq.dto.UserAuthSuccessMsg;
import com.zhuanzhuan.hero.user.service.HeroUserAuthenticationService;
import com.zhuanzhuan.hunter.mq.consumer.anno.HunterConsumer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ClassName AuthenticationConsumer
 * @Description 实人认证、企业认证 相关
 * @Author hanjunjun
 * @Date 2024/6/27 15:56
 */
@Slf4j
@Component
public class AuthenticationConsumer {

    @Resource
    private HeroUserAuthenticationService userAuthService;

    /**
     * 实人认证结果mq
     *
     * @param msgId
     * @param body
     * @return boolean
     * @author  hanjunjun
     * @date 2024/6/27
     **/
    @HunterConsumer(topic = "multi_certification_success", group = "real_name_auth_hero_user")
    public boolean realnameAuthResult(String msgId, UserAuthSuccessMsg body) {
        log.info("realnameAuthResult msgId={} body={}", msgId, JsonUtils.toJsonWithoutNull(body));
        if (!Consts.AUTH_SOURCE_CODE.equals(body.getSourceCode())) {
            log.info("不是侠客汇认证来源");
            return true;
        }

        return userAuthService.realnameAuthSuccess(body.getUid());
    }

    @HunterConsumer(topic = "license_auth_success", group = "enterprise_auth_hero_user")
    public boolean enterpriseAuthResult(String msgId, UserAuthSuccessMsg body) {
        log.info("enterpriseAuthResult msgId={} body={}", msgId, JsonUtils.toJsonWithoutNull(body));
        if (!Consts.ENTERPRISE_AUTH_CODE.equals(body.getSourceCode())) {
            log.info("不是侠客汇认证来源");
            return true;
        }

        return userAuthService.enterpriseAuthSuccess(body.getUid());
    }
}
